package com.cssy.yd.basic.service.impl;

import java.util.Date;
import java.util.List;

import javax.annotation.Resource;

import org.springframework.dao.DataAccessException;
import org.springframework.stereotype.Service;

import com.byd.acegiext.domain.User;
import com.cssy.yd.basic.dao.BasicMeasurementUnitDAO;
import com.cssy.yd.basic.entity.BasicMaterialsDO;
import com.cssy.yd.basic.entity.BasicMeasurementUnitDO;
import com.cssy.yd.basic.service.IBasicMeasurementUnitService;
import com.plat.exception.SyBaseException;
import com.plat.helper.SearchConditions;
import com.plat.helper.SearchResult;
import com.plat.util.IDCodeTypeUtil;

@Service("basicMeasurementUnitService")
public class BasicMeasurementUnitService implements IBasicMeasurementUnitService {

	@Resource(name="basicMeasurementUnitDAO")
	private BasicMeasurementUnitDAO basicMeasurementUnitDAO;
	
	@Override
	public SearchResult findListByExample(SearchConditions scs)
			throws SyBaseException {
		SearchResult rs=new SearchResult(scs);
		List<BasicMeasurementUnitDO>  list=basicMeasurementUnitDAO.find(scs);
		rs.setRecordCount(basicMeasurementUnitDAO.count(scs));
		rs.setResults(list);
		return rs;
	}

	@Override
	public Integer delete(String id, User user) throws SyBaseException {
		basicMeasurementUnitDAO.deleteBasicMeasurementUnitDOByPrimaryKey(id);
		return null;
	}

	@Override
	public Integer update(BasicMeasurementUnitDO t, User user)
			throws SyBaseException {
		if((t.getDefaultUnit()==null?1:t.getDefaultUnit()) == 0){
			t.setUnitconvert(1.0);
		}
		t.setDuuser(user.getName());
		t.setDutime(new Date());
		return basicMeasurementUnitDAO.updateBasicMeasurementUnitDO(t);
	}

	@Override
	public BasicMeasurementUnitDO save(BasicMeasurementUnitDO t, User user)
			throws SyBaseException {
		if((t.getDefaultUnit()==null?1:t.getDefaultUnit()) == 0){
			t.setUnitconvert(1.0);
		}
		t.setDcruser(user.getName());
		t.setDctime(new Date());
		t.setId(IDCodeTypeUtil.getId());
		basicMeasurementUnitDAO.insertBasicMeasurementUnitDO(t);
		return t;
	}

	@Override
	public BasicMeasurementUnitDO findListById(String id)
			throws SyBaseException {
		return basicMeasurementUnitDAO.findBasicMeasurementUnitDOByPrimaryKey(id);
	}

	@Override
	public List<BasicMeasurementUnitDO> findListByExample(
			BasicMeasurementUnitDO bMeasurementUnitDO) throws SyBaseException {

		return basicMeasurementUnitDAO.findListByExample(bMeasurementUnitDO);
	}

	@Override
	public List<BasicMeasurementUnitDO> findWl(String s) throws SyBaseException {
		// TODO Auto-generated method stub
		return basicMeasurementUnitDAO.findWl(s);
	}

	@Override
	public List<BasicMeasurementUnitDO> findUnit(String s) throws DataAccessException {
		// TODO Auto-generated method stub
		return basicMeasurementUnitDAO.findUnit(s);
	}

	@Override
	public Integer deleteBizRemoved(String id) throws SyBaseException {
		// TODO Auto-generated method stub
		return null;
	}
}
